package com.lj.luoye.lotteryticket.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

    public static final int DB_VERSION = 9;
    static final String DB_NAME = "lottery_ticket.db";

    public DBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql_lottery_history = "create table if not exists " +
                "lottery_history" +
                " (id integer primary key AUTOINCREMENT, " +
                "date text, " +
                "redBall1 text, " +
                "redBall2 text, " +
                "redBall3 text, " +
                "redBall4 text, " +
                "redBall5 text, " +
                "redBall6 text, " +
                "blueBall text)";
        db.execSQL(sql_lottery_history);

        String sql_lottery_buy = "create table if not exists " +
                "lottery_buy" +
                " (id integer primary key AUTOINCREMENT, " +
                "date text, " +
                "description text, " +
                "redBall1 text, " +
                "redBall2 text, " +
                "redBall3 text, " +
                "redBall4 text, " +
                "redBall5 text, " +
                "redBall6 text, " +
                "blueBall text," +
                "bought integer," +//0为生成，1为买定
                "luckResult text)";//中奖结果
        db.execSQL(sql_lottery_buy);

        String sql_lottery_buy_multi = "create table if not exists " +
                "lottery_buy_multi" +
                " (id integer primary key AUTOINCREMENT, " +
                "date text, " +
                "description text, " +
                "redBalls text, " +
                "blueBalls text," +
                "bought integer," +//0为生成，1为买定
                "luckResult text)";//中奖结果
        db.execSQL(sql_lottery_buy_multi);

        String sql_register_history = "create table if not exists " +
                "register_history" +
                " (id integer primary key AUTOINCREMENT, " +
                "date text, " +
                "startDate text, " +
                "tryDays integer, " +
                "tryCount integer, " +
                "code text)";//中奖结果
        db.execSQL(sql_register_history);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if(newVersion>oldVersion){
//            String sql1 = "DROP TABLE IF EXISTS lottery_history";
//            db.execSQL(sql1);
//            sql1 = "DROP TABLE IF EXISTS lottery_buy";
//            db.execSQL(sql1);
            String dropRegister="drop table if exists register_history;";
            db.execSQL(dropRegister);
            onCreate(db);
        }
    }
}
